package com.macaline.bean;

import lombok.Data;

/**
 * Service返回处理结果类
 */
@Data
public class Result {

    private int result = 1; // 处理结果 0：失败；1：成功。
    private String info; // 失败原因
    private Object data; // 返回数据


    public Result(int result) {
        this.result = result;
    }
    public Result() {
    }

    public Boolean isSuc(){
        return result == 1;
    }

    public Result(int result, String info) {
        this.result = result;
        this.info = info;
    }


    /**
     *
     * @return
     */
    public static Result success() {
        return new Result(1,"");
    }

    public static Result success(Object data) {
        Result success = success();
        success.setData(data);
        return success;
    }

    /**
     *
     * @param info
     * @return
     */
    public static Result error(String info) {
        return new Result(0,info);
    }

    public static Result error() {
        return new Result(0, "操作失败");
    }

    @Override
    public String toString() {
        return "ServiceResult{" +
                "result=" + result +
                ", info='" + info + '\'' +
                ", data=" + data +
                '}';
    }
}
